require "Common/define"
require "Controller/PromptCtrl"
require "Controller/MessageCtrl"
require "Logic/GameMainCtrlManager"

CtrlManager = {};
local this = CtrlManager;
local ctrlList = {};	--控制器列表--
local OpenList = {} --打开的面板合集

CtrlNames = {}

function CtrlManager.Init()
	-- logWarn("CtrlManager.Init----->>>");
	-- ctrlList[CtrlNames.Prompt] = PromptCtrl.New();
	-- ctrlList[CtrlNames.Message] = MessageCtrl.New();
	GameMainCtrlManager:Init()
	return this;
end

--添加控制器--
function CtrlManager.AddCtrl(ctrlName, ctrlObj)
	ctrlList[ctrlName] = ctrlObj;
end

--获取控制器--
function CtrlManager.GetCtrl(ctrlName)
	return ctrlList[ctrlName];
end

--移除控制器--
function CtrlManager.RemoveCtrl(ctrlName)
	ctrlList[ctrlName] = nil;
end

--关闭控制器--
function CtrlManager.Close(ctrlName)
	logWarn('CtrlManager.Close---->>>'..ctrlName);
	if OpenList[ctrlName] ~= nil then
		OpenList[ctrlName] = nil
	end
end

function CtrlManager.ClosePanel(ctrlName)
	if OpenList[ctrlName] ~= nil then
		OpenList[ctrlName]:ClosePanel()
	end
end

function CtrlManager.ShowPanel(ctrlName,data,layout)
	if OpenList[ctrlName] == nil then
		local panel = ctrlList[ctrlName]
		if panel ~= nil then
			local p = panel.New(ctrlName.."Ctrl")
			p:InitData(data,layout)
			p:Awake(ctrlName)
			OpenList[ctrlName] = p
		else
			logError("没有找到控制器 --> "..ctrlName)
		end
	else
		OpenList[ctrlName]:ShowPanel(data)
	end
end

function CtrlManager.SetTotleUpdate(totle)
	if OpenList[CtrlNames.Loading] ~= nil then
		OpenList[CtrlNames.Loading]:SetTotleUpdate(totle)
	end
end

function CtrlManager.SetProgress(index)
	local idx = index + 1
	if OpenList[CtrlNames.Loading] ~= nil then
		OpenList[CtrlNames.Loading]:SetProgress(idx)
	end
end